Skip to content

fix: correct decapsulate for repeated protocols and substring collisions#124

Open
sumanjeet0012 wants to merge 1 commit into
multiformats:masterfrom
sumanjeet0012:fix-issue-109
Open

fix: correct decapsulate for repeated protocols and substring collisions#124
sumanjeet0012 wants to merge 1 commit into
multiformats:masterfrom
sumanjeet0012:fix-issue-109

Conversation

@sumanjeet0012

@sumanjeet0012 sumanjeet0012 commented Jul 13, 2026

Copy link
Copy Markdown

Fixes #109

Description

This pull request fixes a bug where Multiaddr.decapsulate() produced incorrect results when the same protocol appears multiple times in the address, or when the decapsulation target is a substring of a protocol value. The implementation has been updated to compare addresses component-by-component using bytes_iter() instead of performing a raw string search.

Changes

  • Updated Multiaddr.decapsulate in multiaddr/multiaddr.py to match components iteratively instead of using str.rindex().
  • Added tests to tests/test_multiaddr.py containing edge cases for:
    • Repeated protocols
    • Substring collisions
    • Protocol value collisions
  • Added a towncrier newsfragment newsfragments/109.bugfix.

@sumanjeet0012 sumanjeet0012 changed the title Fix: correct decapsulate() for repeated protocols and substring collisions fix: correct decapsulate for repeated protocols and substring collisions Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

decapsulate() uses string rindex — produces incorrect results for repeated protocols

1 participant